// 引入fs模块
const fs = require("fs")
const { resolve } = require("path")

// 回调地狱 实际当中不会这样做，但会有这样的层级
// fs.readFile('./resource/悯农.md', (err, data1) => {
//     fs.readFile('./resource/悯农1.md', (err, data2) => {
//         fs.readFile('./resource/悯农2.md', (err, data3) => {
//             let result = data1 + '\r\n' + data2 + '\r\n' + data3
//             console.log(result);
//         })
//     })
// })

// 使用Promise实现
const p = new Promise((resolve, reject) => {
    fs.readFile("./resource/悯农.md", (err, data) => {
        resolve(data);
    })
})

p.then(value => {
    return new Promise((resolve, reject) => {
        fs.readFile("./resource/悯农1.md", (err, data) => {//这个方法成功，then方法返回的promise也是成功的
            resolve([value, data]);//合并
        })
    })
}).then(value => {
    return new Promise((resolve, reject) => {
        fs.readFile("./resource/悯农2.md", (err, data) => {
            value.push(data);
            resolve(value);
        })
    })
}).then(value=>{
    console.log(`${value}`);
})